package com.edward.service;


import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.edward.PagerModel;
import com.edward.model.BVList;


public class BVListManager extends HibernateDaoSupport {

	public void addBVList(BVList bvList) {
		
		getHibernateTemplate().save(bvList);
	}
	
	public void updateBVList(BVList bvList) {
		
		getHibernateTemplate().update(bvList);
	}
	
	public void deleteBVList(int id){
		
		getHibernateTemplate().delete(getBVList(id));
	}
	
	public BVList getBVList(int id){
		BVList d =(BVList)getHibernateTemplate().get(BVList.class, id);
		return d;
	}
	

	@SuppressWarnings("unchecked")
	public List<BVList> listBVList() {
		return getHibernateTemplate().find("from BVList");
	}

	
	@SuppressWarnings("unchecked")	
	public PagerModel pagerList(int start,int limit) {
		List <BVList>list = getHibernateTemplate().find("from BVList" );
		int total = list.size();
		int toIndex = start + limit;
		if(toIndex>total){
			toIndex =  total;
		}
		List <BVList>datas = list.subList(start, toIndex);
		PagerModel pm = new PagerModel();
		pm.setTotal(total);
		pm.setDatas(datas);
		return pm;
		
	}
	
	@SuppressWarnings("unchecked")	
	public PagerModel pagerList(int start,int limit,String type) {
		List <BVList>list = getHibernateTemplate().find("from BVList b where b.state = '" + type + "'" );
		int total = list.size();
		int toIndex = start + limit;
		if(toIndex>total){
			toIndex =  total;
		}
		List <BVList>datas = list.subList(start, toIndex);
		PagerModel pm = new PagerModel();
		pm.setTotal(total);
		pm.setDatas(datas);
		return pm;
		
	}


}



